package com.jingzhi.mindmap.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;

import com.jingzhi.mindmap.R;
import com.jingzhi.mindmap.model.NodeModel;


/**
 * Created by owant on 09/02/2017.
 */
@SuppressLint("AppCompatCustomView")
public class NodeView extends TextView {
    public NodeModel<String> treeNode = null;

    public NodeView(Context context) {
        this(context, null, 0);
    }

    public NodeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NodeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        setTextColor(0xFFFFFFFF);
        setPadding(12, 10, 12, 10);
        setGravity(Gravity.CENTER);
        Drawable drawable = context.getResources().getDrawable(R.drawable.node_view_bg);
        setBackgroundDrawable(drawable);

    }

    public NodeModel<String> getTreeNode() {
        return treeNode;
    }

//    public void setStyle(Context context,int textColor,int bg,NodeView view){
//        view.setTextColor(textColor);
//        Drawable drawable = context.getResources().getDrawable(bg);
//        view.setBackgroundDrawable(drawable);
//    }

    public void setTreeNode(NodeModel<String> treeNode) {
        this.treeNode = treeNode;
        setSelected(treeNode.isFocus());
        setText(treeNode.getValue());
    }

}